package demo2;

import demo1.Host;
import demo1.Rent;
import demo3.ProxyInvocationHandler;
import org.junit.Test;

public class Try {

    @Test
    public void test1(){
        UserServiceImpl userService = new UserServiceImpl();

        UserServiceProxy userServiceProxy = new UserServiceProxy();
        userServiceProxy.setUserService(userService);

        userService.add();
        userService.delete();
    }
    @Test
    public void test2(){
//        真实角色
        Host host = new Host();
//        代理角色不存在
        ProxyInvocationHandler pih = new ProxyInvocationHandler();
        pih.setRent(host);
//        动态生成代理类
        Rent proxy =(Rent)pih.getProxy();
        proxy.rent();
    }


    @Test
    public void test3(){
//        真实角色
        UserServiceImpl userService = new UserServiceImpl();
//        代理角色不存在
        ProxyInvocationHandler pih = new ProxyInvocationHandler();
        pih.setRent(userService);
//        动态生成代理类
        UserService proxy = (UserService) pih.getProxy();
        proxy.query();
    }
}
